1. Field of the Invention
The present invention relates to a first-in-first-out random access memory (FIFO RAM), and more particularly to an apparatus and method for controlling the access of an asynchronous dual port FIFO memory.
2. Description of Related Art
Metastability, e.g. unstable transient state, is a major problem of controlling an asynchronous dual port FIFO. Different access frequencies in read and write may result in uncertainty of operating addresses specified by a read pointer and a write pointer. For instance, the FIFO control on the write part needs to sample the value of the read pointer for checking the signal FIFO_FULL status with a write clock that is asynchronous to a read clock. Similarly, the FIFO control on the read part needs to sample the value of the write pointer for checking the signal FIFO_EMPTY status with the read clock that is asynchronous to the write clock. However, this may lead to a situation where each bit of the read pointer is changing state from “1” to “0” or “0” to “1”, and every signal bit goes metastable.
The Gray code method is one of the most common approaches to overcome the problem of metastability. Gray code is a unit of distance code; that is, no more than one bit is changed between two adjacent codes. FIG. 1 shows an example of a 3-bit Gray code counter. Gray code method can reduce the metastable bits to the minimum while the pointers are being sampled. The sampled value will at most have one bit error each time. This means that the Gray-coded pointer only changes one bit between two adjacent values. The previous and current values in the counter will be sampled, and the two are corrected for checking FIFO pointers. FIG. 2 illustrates an asynchronous dual port FIFO containing 8 depth of words (not shown). Two 3-bit Gray code pointers 21, 22 (the aforementioned read pointer and write pointer), the different read and write frequencies RCLK, WCLK and their respective synchronizing circuits 210, 220 are used to implement the FIFO. The FIFO is deemed empty (FIFO_EMPTY) when the read point and the write pointer are equal. When the next write pointer value is equal to the current read pointer value through presentations of read and write FIFO status indicators 23, 24, it means the FIFO is full (FIFO_FULL). As such, the read pointer 21 and the write pointer 22 need to be converted to read and write binary counters 25, 26, for indicating read and write addresses of the FIFO, and a subtraction is then performed on the read and write binary counters 27, 28 in order to determine the available space in the FIFO.
Although the Gray code method solves the problem of metastability, it has three disadvantages. First, it is difficult to code the counter in the form of a state machine with the states encoded with Gray code when a long asynchronous FIFO is being implemented. Second, complex detection of FIFO_FULL signal and complicated Gray code arrangement incur problems of timing slacks and large circuit areas. For example, 8 conditions need to be compared to determine whether or not the FIFO is almost full if a 3-bits Gray code counter is implemented. The 8 conditions includes, for example: when the pseudo code in write_pointer is “100” and the pseudo code in read_pointer is “000”, the pseudo code in FIFO_FULL is the value “1”; when the pseudo code in write_pointer is “000” and the pseudo code in read_pointer is “001”, the pseudo code in FIFO_FULL is the value “1”, . . . , etc. Finally, the Gray code method requires Gray-to-binary converters and subtractors to indicate the status of the FIFO. This leads to increased costs. The circuit and equation of an n-bit Gray-to-Binary conversion are shown in FIG. 3, wherein n is any integer more than one. In this example, if the addresses are n-bit wide so the input 31 includes one input line for each of the n bits, wherein n is any integer more than one. The output 32 also includes n individual output lines 34. The n-bit Gray-to-Binary conversion is accomplished using the exclusive OR (XOR) gates 35 and the equations Bn, Bi as shown, wherein n is any integer more than one.